********************************************************************************
* Descriptives: Workplace networks and political selection**********************
********************************************************************************

clear all
clear matrix
set more off, perm
cd "E:/ProjData/Workplace, elite/"
capture log close
log using "C:/Userdata/Shared/Logs/Workplace, elite/descriptive.text", replace text									
do "C:/Userdata/Shared/Dofiles/DoData/Workplace, elite/programs.do"		


use "finaldata.dta", replace

********************************************************************************
* Basic set-ups ****************************************************************
********************************************************************************

global restriction "i_nominated_lag != 1 & i_nominated_lag2 != 1 & i_nominated_lag3 != 1 & i_nominated_lag4 != 1 & i_nominated_lag5 != 1" 	/*First time someone becomes a politician*/					

********************************************************************************
* Descriptive table 
********************************************************************************

eststo clear
estpost sum i_nominated N_wpssyk_lag s_wpssyk_nominated_lag m_wpssyk_nominated_lag if $restriction, listwise detail
esttab using "C:/Userdata/Shared/Output/Workplace, elite/descriptive.tex", cells("mean(fmt(3)) p50(fmt(0)) sd(fmt(3)) min(fmt(0)) max(fmt(0))") replace label compress nonotes  


**************************************************************
****Distribution of main independent variable (appendix) *****
**************************************************************
sum maintreatvar /*0.05*/
sum maintreatvar if maintreatvar>0, d /*mean = 0.33*/

count if maintreatvar==0 /*27,447,689; 85% */

hist maintreatvar, graphregion(color(white))
graph export "C:/Userdata/Shared/Output/Workplace, elite/treatment_distr.pdf", replace as(pdf)
hist maintreatvar if maintreatvar>0, graphregion(color(white))
graph export "C:/Userdata/Shared/Output/Workplace, elite/treatment_distr_2.pdf", replace as(pdf)


********************************************************************************
* Bivariate figures
********************************************************************************

sum i_nominated 
sum i_nominated if i_nominated_lag == 0

destring mandatperiod, replace

gen wplace_pol = . 
replace wplace_pol = 1 if m_wpssyk_nominated_lag > 0 & m_wpssyk_nominated_lag != .
replace wplace_pol = 0 if m_wpssyk_nominated_lag == 0 

bysort mandatperiod wplace_pol: egen desk_nominated = mean(i_nominated)
bysort mandatperiod: egen bench_nominated = mean(i_nominated)
	
collapse desk_nominated bench_nominated, by(wplace_pol mandatperiod)			
drop if mandatperiod == 1

gen polline = desk_nominated if wplace_pol == 1  
gen notpolline = desk_nominated if wplace_pol == 0  

label define mvalues 1 "1998" 2 "2002" 3 "2006" 4 "2010" 5 "2014" 6 "2018"
label values mandatperiod mvalues

twoway (line polline mandatperiod, lcolor(midblue) lpattern(dash)) (line notpolline mandatperiod, lcolor(cranberry) lpattern(longdash)), ///
	ytitle("Probability nominated in t") xtitle("Mandate period") xlabel(2 3 4 5, valuelabel) ///
	graphregion(color(white)) ///
	legend(label(1 "> 0 pols. at w.p., t-1") label(2 "0 pols. at w.p., t-1"))
graph export "C:/Userdata/Shared/Output/Workplace, elite/descfigline.pdf", replace as(pdf)

collapse desk_nominated, by(wplace_pol)
gen desknominated_1 = desk_nominated if wplace_pol == 1 
gen desknominated_0 = desk_nominated if wplace_pol == 0 
keep desknominated_*
graph bar (mean) desknominated_1 (mean) desknominated_0, bar(1, fcolor(midblue)) bar(2, fcolor(cranberry)) graphregion(color(white)) ytitle("Probability nominated in t") legend(label(1 "> 0 pols. at w.p., t-1") label(2 "0 pols. at w.p., t-1"))
graph export "C:/Userdata/Shared/Output/Workplace, elite/descfigbar.pdf", replace as(pdf)



**************
clear all
log close
